<!--
* description: 获取厂家客户信息
* author: dxuem
* createdDate: 2019-12-16
-->
<template>
  <section class="getOemCustInfo">
    <el-dialog v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      @close="close"
      width="1000px"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-params">
        <el-row>
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
            :inputType="comp.type"
            :comType="comp.comType"
            :isMul="comp.isMul"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { oneTableTemplateMixins } from "@/components/mixins/oneTableTemplateMixins";
import { formMixins } from "@/components/mixins/formMixins";
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
export default {
  // 组件混入对象
  mixins: [formMixins],
    components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: crmApis.mdmDlrCustInfoMutationCopyByPV, //获取厂家客户信息
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.getCustInfo(),
          text: "获取"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          span: 8,
          compKey: "compKey1",
          labelName: "VIN码",
          codeField: "vin",
          isRequire: false,
          component: () => import("@/components/crm/textbox/crmTextInput"),
          type: "inputText",
          disabled: true,
          isMust: true
        },
        // {
        //   compKey: "compKey2",
        //   labelName: "电话",
        //   codeField: "phone",
        //   isRequire: false,
        //   component: () => import("@/components/crm/textbox/crmTextInput"),
        //   type: "text",
        //   // disabled: this.formField.custClassCode==="0"?false:true,
        //   isMust: true
        // },
        // {
        //   compKey: "compKey3",
        //   labelName: "车牌号",
        //   codeField: "carLicense",
        //   isRequire: false,
        //   lookuptype: "1016",
        //   component: () => import("@/components/crm/textbox/crmTextInput"),
        //   type: "text",
        //   isMust: true
        // }
      ],
      // 标题
      textMap: {
        edit: "获取厂家客户信息",
        add: "获取厂家客户信息"
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        vin: "",
        phone: "",
        carLicense: ""
      }
    };
  },
  methods: {
    //保存
    getCustInfo() {
      let that = this;
      let queryObj = {
          type: "mutation",
          apiConfig: crmApis.mdmDlrCustInfoMutationCopyByPV, //专营店客户信息-新增客户
          apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: [
              "dlrCustNo",
              "custNo",
              "custClassCode",
            ]
          }],
          variables: {
            dataInfo: this.formField
          }
        };
        var paramD = that.$getParams(queryObj);
        requestAPI(paramD).then(response => {
          if (response.data[queryObj.apiConfig.ServiceCode].result == "1") {
            this.$parent.editPopupsVisible = false;
            this.curPopupsVisible=false
            that.$crmcf.showMessages(that, "success", "获取成功！");
            var result=response.data[queryObj.apiConfig.ServiceCode].rows;
            debugger
            result.vin=that.formField.vin;
            result.getOEM='1'
            result.carInfo='1'
            this.$emit("getResult",result)
            if(!this.$parent.input_type){
              // this.$parent.$refs.multipleTable.query();
              this.$router.push({ name: 'changeowner', params:result});
            }
            // this.$parent.queryTable(1);

          } else {
            that.$crmcf.showMessages(
              that,
              "error",
              response.data[queryObj.apiConfig.ServiceCode].msg
            );
          }
        });
      // if (that.formField.phone == "" && that.formField.carLicense == "") {
      //   this.$message({
      //     message: "电话和车牌号不能同时全部为空！",
      //     type: "warning"
      //   });
      // } else {
      //   let queryObj = {
      //     type: "mutation",
      //     apiConfig: crmApis.mdmDlrCustInfoMutationCopyByPV, //专营店客户信息-新增客户
      //     apiServices: [
      //     {
      //       //表格中台返回网格的字段
      //       apiQueryRow: [
      //         "dlrCustNo",
      //         "custNo",
      //         "custClassCode",
      //       ]
      //     }],
      //     variables: {
      //       dataInfo: this.formField
      //     }
      //   };
      //   var paramD = that.$getParams(queryObj);
      //   requestAPI(paramD).then(response => {
      //     if (response.data[queryObj.apiConfig.ServiceCode].result == "1") {
      //       this.$parent.editPopupsVisible = false;
      //       this.curPopupsVisible=false
      //       that.$crmcf.showMessages(that, "success", "获取成功！");
      //       var result=response.data[queryObj.apiConfig.ServiceCode].rows;
      //       debugger
      //       result.vin=that.formField.vin;
      //       if(!this.$parent.input_type){
      //         // this.$parent.$refs.multipleTable.query();
      //         this.$router.push({ name: 'changeowner', params:result});
      //       }
      //       // this.$parent.queryTable(1);
      //       this.$emit("getResult",result)
      //     } else {
      //       that.$crmcf.showMessages(
      //         that,
      //         "error",
      //         response.data[queryObj.apiConfig.ServiceCode].msg
      //       );
      //     }
      //   });
      // }
    },
    close() {
      this.$parent.editPopupsVisible = false;
    }
  }
};
</script>
